package chapter10.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DbUtils {
    /**
     * 获得连接
     * @return
     */
    public static Connection getConnection() throws ClassNotFoundException, SQLException {
        // 1. 注册数据库的驱动
        Class.forName("com.mysql.cj.jdbc.Driver");
        // 2.通过DriverManager获取数据库连接
        String url =
                "jdbc:mysql://localhost:3306/jdbc?characterEncoding=utf-8";
        String username = "root";
        String password = "root";
        Connection conn = DriverManager.getConnection(url, username, password);
        return conn;
    }

}
